<template>
    <div>
        <table>
            <tr>
                <td>户型名称</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>户型结构</td>
                <td>
                    <select v-model="data.hunt">
                        <option value="0">请选择</option>
                        <option value="一层结构">一层结构</option>
                        <option value="两层结构">两层结构</option>
                        <option value="三层结构">三层结构</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>建筑面积</td>
                <td><input type="text" v-model="data.jian"></td>
            </tr>
            <tr>
                <td>套内面积</td>
                <td><input type="text" v-model="data.teao"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                    <input type="file" @change="Tent">
                    <img :src="'https://localhost:7095'+data.img" alt="" style="width: 90px;height: 90px;">
                </td>
            </tr>
            <tr>
                <td>启禁用</td>
                <td>
                    <input type="radio" v-model="data.quent" :value="true">启用
                    <input type="radio" v-model="data.quent" :value="false">禁用
                </td>
            </tr>
            <tr>
                <td><input type="button" value="修改" @click="Xin"></td>
                <a href='/ShowView'>返回</a>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter ,useRoute} from 'vue-router';

const rount=useRoute()
const rountr=useRouter()

onMounted(() => {
    Show()
})

const Tent=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();
    fd.append("file",f);
    axios.post("https://localhost:7095/api/Uplog",fd).then(res=>{
        data.value.img=res.data;
    })

}

const data=ref({
  "id": 0,
  "name": "",
  "hunt": "0",
  "jian": 0,
  "teao": 0,
  "img": "",
  "quent": true
})

const Show=()=>{
    var vid=rount.query.id;
    axios.get("https://localhost:7095/api/User/GetUplt",{params:{id:vid}}).then(res=>{
        data.value=res.data;
    })
}


const Xin=()=>{
    axios.post("https://localhost:7095/api/User/Update",data.value).then(res=>{
        if(res.data>0){
            alert('成功')
            rountr.push({path:'/ShowView'})
        }
        else{
            alert('失败')
        }
    })
}



</script>

<style scoped>

</style>